
import {config} from "./config.js";
App({
  onLaunch: function (options) {

    var that = this;
    if (options.scene == 1044 || options.scene == 1044 || options.path.indexOf("wxlogin")!=-1){
      wx.getShareInfo({
        shareTicket:options.shareTicket,
        success:function(res){
          let encryptedData = res.encryptedData
          let iv = res.iv;
        }
      })
    }
    try {
      const res = wx.getSystemInfoSync();
      console.log("设备信息",res)
      that.globalData.windowWidth = res.windowWidth;
      that.globalData.windowHeight = res.windowHeight;
      that.globalData.deviceInfo = res.model + '|' + res.system + '|'+res.SDKVersion;
      wx.setStorageSync("deviceInfo", that.globalData.deviceInfo);
    } catch (e) {
      // Do something when catch error
    }
    // 获取用户信息
    let currentUser = wx.getStorageSync("userInfo");
    if (currentUser != "" && currentUser.nickName) {
      this.globalData.userInfo = currentUser;
    }
 
    if (options.path.indexOf("board") != -1 ){
      wx.redirectTo({
        url:"/"+options.path,
        success: function () {
        }
      })
      return;
    }
    if (options.path.indexOf("wxlogin") == -1) {
      wx.redirectTo({
        url: '/pages/wxlogin/wxlogin?toPath='+options.path,
        success: function () {
        }
      })
    }
  },
  onShow: function(options){
    //这块处理是为了修改用户分享名片后　关闭后，再进入小程序还是进入被分享的名片页面
    if (options.path.indexOf("board") != -1 && (options.query.hasOwnProperty("shareUserId"))) {
      let user = wx.getStorageSync("usercache");
      if (options.query.shareUserId == user.userId)
      wx.switchTab({
        url: '/pages/profile/profile'
      })
    }

  },
  globalData: {
    userInfo: null,
    personalInfo:null,
    windowWidth:375,
    windowHeight:667,
    deviceInfo:"",
    isFromSharePage:false
  }
})